#include "Node.h"
#include <iostream>

Node::Node(char _id, bool _bValue)
: m_id(_id), m_value(_bValue)
{
}

Node::~Node(void)
{
}

void	Node::AddCondition(ICondition* _condition)
{
	this->m_conditions.push_back(_condition);
}

void	Node::SetValue(bool _bValue)
{
	this->m_value = _bValue;
}

char	Node::GetId(void) const
{
	return this->m_id;
}

bool	Node::GetBoolean(void) const
{
	if (this->m_conditions.size() == 0)
	{
		std::cout << "Result : " << this->m_id << " => " << std::boolalpha << this->m_value << std::endl;
		return this->m_value;
	}

	std::cout << std::endl << "Searching sub conditions of " << this->m_id << std::endl;
	ConditionsVectorConst::const_iterator it    = this->m_conditions.begin();
	ConditionsVectorConst::const_iterator itEnd = this->m_conditions.end();
	bool bResult = false;
	for (; it != itEnd; ++it)
	{
		if ((*it)->GetBoolean() == true)
		{
			bResult = true;
			break;
		}
	}
	std::cout << "Result = " << this->m_id << " => " << std::boolalpha << bResult << std::endl;
	return bResult;
}

bool	Node::DependsOn		(char nodeId) const
{
	ConditionsVectorConst::const_iterator it =  this->m_conditions.begin();
	ConditionsVectorConst::const_iterator itEnd =  this->m_conditions.end();
	while (it != itEnd)
	{
		if ((*it)->ContainsNode(nodeId))
			return true;
		++it;
	}
	return false;
}
